<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 利用form表单创建post请求
    <form action="postGetpara" method="post">
        <input type="text" name="username">
        <input type="text" name="password">
        <input type="submit" value="提交">
    </form> -->
   <!--用ajax创建post请求-->
   <input type="text" id="username">
   <input type="text" id="password">
   <input type="button"value="提交" id="submit">
   <script src="https://lib.baomitu.com/jquery/3.6.3/jquery.min.js"></script>
   <script>
    let uerInput=document.querySelector("#username");
    let passInput=document.querySelector("#password");
    let but=document.querySelector("#submit");
    but.onclick=function(){
        $.ajax({
            //方法
            type:'post',
            //路径
            url:'postJson',
            //数据
            contentType:'application/json',
            data:JSON.stringify({
                username:uerInput.value,
               password: passInput.value,

            }),
            success:function(body){
               console.log(body);
            }
        })
    }
   </script>
</body>
</html>